<?
    require_once("mvc/action/Action.php");
    require_once("cms/customer/om/CustomerPeer.php");
    require_once("cms/newsletter/om/NewsletterCustomerPeer.php");

    class ReceipientAction extends Action {

        private $log;

        public function __construct() {
            $this->log =& LoggerManager::getLogger("ReceipientAction");
        }

        public function execute(ActionConfig &$mapping, &$form, Request &$request, Response &$response) {

            if($form->getId() === null)
                return $mapping->findForward("noid");

            if($mapping->getPath() == "/recipient/filter")
                return $mapping->findForward("success");

            $recipients = array();

            $c = new Criteria();
            $c->clearSelectColumns();
            $c->addSelectColumn(NewsletterCustomerPeer::CUSTOMER_ID);
            $c->add(NewsletterCustomerPeer::NEWSLETTER_ID, $form->getId());
            $rs = CustomerPeer::doSelectRS($c);
            while($rs->next()) {
                $recipients[] = $rs->getInt(1);
            }

            $form->setRecipients($recipients);

            return $mapping->findForward("success");

        }

    }
?>